<template>
  <div class="navC-container">
    <div class="nav">
      <div class="content">
        <div v-for="(item, i) in array" :key="i" class="item">
          <div :class="{ text: item.hasContent }">{{ array[i].content }}</div>
          <div class="list" v-if="item.hasContent">
            <div v-for="ctx in item.ctx">
              <a href="#">{{ ctx }}</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Carousel />
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import Carousel from "./Carousel.vue";
import { getNav } from "../api/otherAPI.js";

let array = ref([]);

(async () => {
  onMounted(async () => {
    array.value = await getNav();
  });
})();
</script>

<style scoped>
.navC-container {
  width: 100%;
  height: 500px;
  overflow: hidden;
}

.nav {
  background-color: #0e9fed;
  height: 50px;
}

.content {
  position: relative;
  height: 100%;
  width: fit-content;
  background-color: #0e9fed;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.item:hover {
  background-color: #5dc2ed;
  cursor: pointer;
}

.item {
  width: 120px;
  height: 100%;
  display: inline-block;
  text-align: center;
  line-height: 50px;
  color: white;
  position: relative;
  z-index: 99;
}

.content > div:first-child {
  background-color: #007bf5;
}

.text::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid white;
  position: absolute;
  top: 24px;
}

.list {
  visibility: hidden;
  background-color: white;
}

.list div {
  width: 100%;
  height: 80%;
}

.text:hover + .list,
.list:hover {
  visibility: visible;
}

.list a:hover {
  color: dodgerblue;
}
</style>
